package cn.edu.nju.software.cdiy.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import cn.edu.nju.software.cdiy.bean.Brand;
import cn.edu.nju.software.cdiy.bean.Hardware;
import cn.edu.nju.software.cdiy.bean.HardwareSet;
import cn.edu.nju.software.cdiy.bean.Memory;
import cn.edu.nju.software.cdiy.bean.Scheme;
import cn.edu.nju.software.cdiy.dao.MemoryDao;
import cn.edu.nju.software.cdiy.dao.SchemeDao;
import cn.edu.nju.software.cdiy.service.Service;
import cn.edu.nju.software.cdiy.service.UtilService;
import cn.edu.nju.software.cdiy.util.BusinessConstant;
import cn.edu.nju.software.cdiy.util.Item;
import cn.edu.nju.software.cdiy.util.SortType;
import cn.edu.nju.software.cdiy.util.SortWay;

public class MemoryServiceImpl implements Service<Memory> {
	
	@Autowired
	private MemoryDao memoryDao;
	@Autowired
	private SchemeDao schemeDao;
	@Autowired
	private UtilService utilService;

	public void setMemoryDao(MemoryDao memoryDao) {
		this.memoryDao = memoryDao;
	}

	public void setSchemeDao(SchemeDao schemeDao) {
		this.schemeDao = schemeDao;
	}

	public void setUtilService(UtilService utilService) {
		this.utilService = utilService;
	}

	public List<Memory> getMemList(int p, SortType s, HardwareSet hs, SortWay sw) {
		return memoryDao.getMemList(p, s, utilService.fillHardwareSet(hs), sw);
	}
	
	public List<Hardware> getNewestList() {
		return memoryDao.getNewestList();
	}
	
	public List<Hardware> getHottestList() {
		return memoryDao.getHottestList();
	}
	
	public List<Brand> getBrandList() {
		return memoryDao.getBrandList();
	}
	
	public List<Memory> filter(int page,Map<String, List<Integer>> map,SortType st,SortWay sw,HardwareSet hs) {
		return memoryDao.filter(page ,map, st, sw, utilService.fillHardwareSet(hs));
	}
	
	public List<Memory> search(String keywords,int page) {
		return memoryDao.search(keywords, page);
	}
	
	public Map<String,List<Item>> getFilterBoard() {
		return memoryDao.getFilterBoard();
	}
	
	public Memory getOneById(int id) {
		return memoryDao.getOneById(id);
	}
	
	public Map<String, List<String>> getInsertboard() {
		return memoryDao.getInsertboard();
	}
	
	public boolean insertHardware(Map<String, List<String>> map) {
		return memoryDao.insertHardware(map);
	}
	
	public void save(Memory t) {
		memoryDao.save(t);
	}
	
	public int getFilterResultLength(Map<String, List<Integer>> map,HardwareSet hs) {
		return memoryDao.filterPageNum(map, utilService.fillHardwareSet(hs));
	}
	
	public int getListPageNum(HardwareSet hs) {
		return memoryDao.getListPageNum(utilService.fillHardwareSet(hs));
	}

	@Override
	public List<Scheme> getRelatedSchemes(int hardwareId) {
		return schemeDao.getFourScheme(hardwareId, BusinessConstant.H_MEMORY);
	}
	
	@Override
	public List<Memory> getSupplierHarewares(int id) {
		// TODO Auto-generated method stub
		return memoryDao.getOneBySupplierID(id);
	}
}
